package com.engine.core.interceptor;

import com.engine.core.gen.Global;
import com.ql.util.express.IExpressContext;

import java.util.AbstractMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by wcc on 2017/11/6.
 */
public class CommandContext extends AbstractMap<String, Object> implements IExpressContext<String, Object> {


    protected Throwable exception;
    protected Global global;



    protected Map<String, Object> attributes=new ConcurrentHashMap<>();

    protected boolean reused;

    public CommandContext() {
    }

    public CommandContext(Global global) {
        this.global = global;
    }

    protected void logException() {
    }

    public void close() {
        //TODO
    }

    public boolean isReused() {
        return reused;
    }

    public void setReused(boolean reused) {
        this.reused = reused;
    }

    public Throwable getException() {
        return exception;
    }

    public void setException(Throwable exception) {
        this.exception = exception;
    }

    public Map<String, Object> getAttributes() {
        return attributes;
    }

     @Override
    public Object put(String key, Object value) {
        this.attributes.put(key,value);
        return value;
    }

    @Override
    public Set<Entry<String, Object>> entrySet() {
        return this.attributes.entrySet();
    }


    public Object remove(String key) {
        return attributes.remove(key);
    }

    public Global getGlobal() {
        return global;
    }

    public void setGlobal(Global global) {
        this.global = global;
    }

    public void setAttributes(Map<String, Object> attributes) {
        this.attributes.putAll(attributes);
    }


}

